if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_HangHoa_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_HangHoa_Insert]
GO
CREATE PROC [sp_HangHoa_Insert]
	@MaHang					nvarchar(30),
	@TenHang				nvarchar(50),
	@TenNhomHang			nvarchar(50),
	@Barcode				nvarchar(500),
	@MoTa					nvarchar(2000),
	@Hinh					nvarchar(500),
	@Thue					int,
	@ChietKhau				int,
	@GiaNhap				float,
	@GiaBanSi				float,
	@GiaBanLe				float,
	@MaDonViQuiDoi			int,
	@DinhMucTon				float,
	@GhiChu				nvarchar(2000)
AS
BEGIN
	DECLARE @MaNhomHang int
		SELECT @MaNhomHang = ID FROM NhomHang WHERE Ten = @TenNhomHang
	DECLARE @Ngay_cap_nhat_cuoi datetime
		SET @Ngay_cap_nhat_cuoi = getdate()
		
	INSERT INTO HangHoa(
					Ma_hang,
					Ten,
					Ma_nhom_hang,
					Ghi_chu,
					Ma_don_vi_qui_doi,
					Thue,
					Chiet_Khau,
					Gia_nhap,
					Gia_ban_si,
					Gia_ban_le,
					Ton_dinh_muc,
					Mo_ta,
					Hinh,
					Barcode_new,
					Ngay_cap_nhat_cuoi
				)
		VALUES(				
			@MaHang,
			@TenHang,
			@MaNhomHang,
			@GhiChu,
			@MaDonViQuiDoi,
			@Thue,
			@ChietKhau,
			@GiaNhap,
			@GiaBanSi,
			@GiaBanLe,
			@DinhMucTon,
			@MoTa,
			@Hinh,
			@Barcode,
			@Ngay_cap_nhat_cuoi
		)
END
